package com.gzdh.dishrecognition.ui.fragment.sysset;

import static com.gzdh.dishrecognition.util.BitmapUtils.drawableToBitmap;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.StateListDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ScrollView;

import androidx.fragment.app.Fragment;

import com.gzdh.dishrecognition.R;
import com.gzdh.dishrecognition.ui.dialog.identify.CameraSettingDialogFragment;
import com.gzdh.dishrecognition.ui.view.OptionItemView;

/**
 * 菜品识别设置
 */
public class IdentifySystemSetFragment extends Fragment {
    private Context mContext;

    private OptionItemView regView;

    public IdentifySystemSetFragment() {
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mContext = inflater.getContext();
        View view = getViews();
        init();
        return view;
    }

    private View getViews() {
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
        LinearLayout mainLayout = new LinearLayout(mContext);
        mainLayout.setLayoutParams(layoutParams);
        mainLayout.setBackgroundColor(Color.WHITE);
        mainLayout.setOrientation(LinearLayout.VERTICAL);
//        mainLayout.addView(getTitleView());   //标题初始化
        mainLayout.addView(getBody());        //主题内容
        return mainLayout;
    }


    private View getBody() {
        ScrollView scrollView = new ScrollView(mContext);
        scrollView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        StateListDrawable selector = new StateListDrawable();

        selector.addState(new int[]{android.R.attr.state_pressed}, getResources().getDrawable(R.color.gray8));
        selector.addState(new int[]{android.R.attr.state_selected}, getResources().getDrawable(R.color.white));
        selector.addState(new int[]{}, getResources().getDrawable(R.color.white));


        LinearLayout mainLinear = new LinearLayout(mContext);
        mainLinear.setOrientation(LinearLayout.VERTICAL);
        scrollView.addView(mainLinear);

        regView = new OptionItemView(mContext);
        int heightInPx = (int)(45 * getResources().getDisplayMetrics().density);
        LinearLayout.LayoutParams linearParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, heightInPx);
        regView.setLayoutParams(linearParams);
        regView.setPadding(20, 20, 20, 20);
        regView.setBackground(selector);
        regView.setLeftImageMarginLeft(20);
        regView.setLeftImageMarginRight(18);
        regView.setLeftImage(drawableToBitmap(getResources().getDrawable(R.mipmap.setting_icon)));
        regView.setLeftText("菜品摄像头设置");
        regView.setLeftTextSize(16);
        regView.setLeftTextColor(Color.BLACK);
        regView.setRightImage(drawableToBitmap(getResources().getDrawable(R.mipmap.enter_icon)));
        regView.setOnClickListener(view -> {
            Bundle bundle = new Bundle();
            CameraSettingDialogFragment cameraSettingDialogFragment = new CameraSettingDialogFragment();
            cameraSettingDialogFragment.show(getChildFragmentManager(), CameraSettingDialogFragment.class.getSimpleName());
        });
        mainLinear.addView(regView);

        View line = new View(mContext);
        line.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 1));
        line.setBackgroundColor(Color.rgb(224, 224, 224));
        mainLinear.addView(line);

        OptionItemView menuLinView = new OptionItemView(mContext);
        menuLinView.setPadding(20, 20, 20, 20);
        menuLinView.setLayoutParams(linearParams);
        selector = new StateListDrawable();
        selector.addState(new int[]{android.R.attr.state_pressed}, getResources().getDrawable(R.color.gray8));
        selector.addState(new int[]{android.R.attr.state_selected}, getResources().getDrawable(R.color.white));
        selector.addState(new int[]{}, getResources().getDrawable(R.color.white));
        menuLinView.setBackground(selector);
        menuLinView.setLeftImageMarginLeft(20);
        menuLinView.setLeftImageMarginRight(18);
        menuLinView.setLeftImage(drawableToBitmap(getResources().getDrawable(R.mipmap.setting_icon)));
        menuLinView.setLeftText("菜品图片压缩");
        menuLinView.setLeftTextSize(16);
        menuLinView.setLeftTextColor(Color.BLACK);
        menuLinView.setRightImage(drawableToBitmap(getResources().getDrawable(R.mipmap.enter_icon)));

        menuLinView.setOnClickListener(view -> {

        });
        mainLinear.addView(menuLinView);

        line = new View(mContext);
        line.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 1));
        line.setBackgroundColor(Color.rgb(224, 224, 224));
        mainLinear.addView(line);

        OptionItemView internalLineView = new OptionItemView(mContext);
        internalLineView.setPadding(20, 20, 20, 20);
        internalLineView.setLayoutParams(linearParams);
        selector = new StateListDrawable();
        selector.addState(new int[]{android.R.attr.state_pressed}, getResources().getDrawable(R.color.gray8));
        selector.addState(new int[]{android.R.attr.state_selected}, getResources().getDrawable(R.color.white));
        selector.addState(new int[]{}, getResources().getDrawable(R.color.white));
        internalLineView.setBackground(selector);
        internalLineView.setLeftImageMarginLeft(20);
        internalLineView.setLeftImageMarginRight(18);
        internalLineView.setLeftImage(drawableToBitmap(getResources().getDrawable(R.mipmap.setting_icon)));
        internalLineView.setLeftText("补光灯");
        internalLineView.setLeftTextSize(16);
        internalLineView.setLeftTextColor(Color.BLACK);
         internalLineView.setRightImage(drawableToBitmap(getResources().getDrawable(R.mipmap.enter_icon)));
        internalLineView.setOnClickListener(view -> {

        });
        mainLinear.addView(internalLineView);
        return scrollView;
    }




    private void init() {


    }


}
